package com.example.freemarker.template;

import com.example.annotations.Autowired;
import com.example.annotations.Compontent;
import com.example.flowable.model.FlowableModel;
import com.example.flowable.model.FormModel;
import com.example.flowable.model.TableModel;
import com.example.flowable.service.FlowableModelService;
import com.example.flowable.service.FormModelService;
import com.example.flowable.service.TableModelService;
import com.example.freemarker.config.DirectiveHandler;
import com.example.freemarker.config.FreemarkerCompontent;
import com.example.freemarker.config.TemplateDirective;

/**
 * @Classname FormModelTemplate
 * @Description TODO
 * @Date 2022/8/16 14:23
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@FreemarkerCompontent("FormModel")
@Compontent
public class FormModelTemplate extends TemplateDirective {

    @Autowired
    private FlowableModelService flowableModelService;

    @Autowired
    private TableModelService tableModelService;

    @Override
    public String getName() {
        return "FormModel";
    }

    @Override
    public void execute(DirectiveHandler handler) throws Exception {
        String modelId=handler.getString("fromId");
        TableModel tableModel=tableModelService.getById(modelId);
        handler.put(RESULT,tableModel).render();
    }
}
